package ModelLayer;
import java.util.ArrayList;

/**
 * Write a description of class ListEmployees here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class EmployeeContainer
{
    private static ArrayList<Employee> employeeList = new ArrayList<Employee>();
    
    /**
     * Constructor for objects of class ListEmployees
     */
    public EmployeeContainer()
    {
        
    }
    
    public Employee getEmployee(long _id)
    {
        Employee e = new Employee();
        e = null;
        for (int i=0; i<employeeList.size(); i++)
        {
            if (employeeList.get(i).getId() == _id)
            { 
                e = employeeList.get(i);
                return e;
            }
            else
                e = null;
        }
        
        return e;
    }
    
    public void createEmployee(Employee _employee)
    {
        employeeList.add(_employee);
    }
    
    public void updateEmployee(Employee _employee)
    {
       getEmployee(_employee.getId()).setFirstName(_employee.getFirstName());
       getEmployee(_employee.getId()).setLastName(_employee.getLastName());
       getEmployee(_employee.getId()).setBankAccount(_employee.getBankAccount());
       getEmployee(_employee.getId()).setEmail(_employee.getEmail());
       getEmployee(_employee.getId()).setPhone(_employee.getPhone());
       getEmployee(_employee.getId()).setAddress(_employee.getAddress());
       getEmployee(_employee.getId()).setCity(_employee.getCity());
       getEmployee(_employee.getId()).setCpr(_employee.getCpr());
       getEmployee(_employee.getId()).setFunction(_employee.getFunction());
       getEmployee(_employee.getId()).setSalary(_employee.getSalary());
       getEmployee(_employee.getId()).setCredentials(_employee.getCredentials());
       getEmployee(_employee.getId()).setDepartment(_employee.getDepartment());
    }
    
    public void removeEmployee(long _id)
    {
        for(int i=0; i<employeeList.size(); i++)
        {
            if(employeeList.get(i).getId() == _id)
            {
                employeeList.remove(i);
            }
        }
    }
    
    public ArrayList<Employee> listAllEmployees()
    {
        return employeeList;
    }
}
